const {
	app,
	BrowserWindow,
	Menu
} = require('electron'); //引入electron


const http = require('http');
const exp = require('./app/app');
const conf = require('./sys-config');
const path = require ('path');

// 获取安装目录（也就是文件安装目录中exe文件的目录）
let homeDir =  path.dirname(app.getPath('exe'))
/******开启后端监听******/
exp.set('port', conf.app.host);
// 设置全局变量，安装目录
global.homeDir = homeDir
const server = http.createServer(exp);
server.listen(conf.app.host);

/******配置窗体******/

// 隐藏菜单栏
Menu.setApplicationMenu(null)
let win;

function createWindow() {
	win = new BrowserWindow(conf.browserWindow); //创建一个窗口
	// win.loadURL(`http://localhost:${conf.app.host}`); //打包完成
	win.loadURL(`http://localhost:${conf.frontend.host}`); //开发时调试
	win.webContents.openDevTools(); //开启调试工具
	win.on('close', () => {
		//回收BrowserWindow对象
		win = null;
	});
	// win.on('resize', () => {
	//     win.reload();
	// })
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
	app.quit();
});
app.on('activate', () => {
	if (win == null) {
		createWindow();
	}
});
